﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ScannerDemo.common
{
    class DataValidator
    {
        public bool IsValidEmail(string email)
        {
            try
            {
                if (email == "")//email可以为空
                    return true;

                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Match match = regex.Match(email);
                if (match.Success)
                    return true;
                else
                    return false;

            }
            catch (FormatException)
            {
                return false;
            }
        }
        public bool IsValidName(string name)
        {
            try
            {

                if (name == "")//name不能为空
                    return false;
                else if (name.Length < 30)
                    return true;
            }
            catch (FormatException)
            {
                return false;
            }
            return true;
        }
        public bool IsValidText(string text)
        {
            try
            {

                if (text == "")//name不能为空
                    return false;
                else if (text.Length < 100)
                    return true;
            }
            catch (FormatException)
            {
                return false;
            }
            return true;
        }
        public bool IsValidUrl(string url)
        {
            try
            {
                if (url == "")
                    return false;

                //Regex regex = new Regex(@"\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]");
                Regex regex = new Regex(@"\b(https?|ftp)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]");
                Match match = regex.Match(url);
                if (match.Success)
                    return true;
                else
                    return false;

            }
            catch (FormatException)
            {
                return false;
            }
        }

    }


}
